package cn.school.demo.ui.article

import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import cn.school.demo.pojo.Article
import cn.school.demo.pojo.Result
import cn.school.demo.repository.ArticleRepository

class ViewPagerViewModel : ViewModel() {

    private val _articleList = mutableListOf<Article>()
    val articleList: MutableList<Article> get() = _articleList

    private val _chartArticleList = mutableListOf<Article>()
    val chartArticleList: MutableList<Article> get() = _chartArticleList

    var newY: Float = 0f
    var oldY: Float = 0f
    var isBottom = false
    var isTop = false
    private val _pageSize = 10
    val pageSize: Int get() = _pageSize
    private var pageNum = 1

    fun getArticleByHobbyName(hobbyName: String): LiveData<MutableList<Article>> =
        ArticleRepository().getArticleByHobbyName(hobbyName, 1, pageSize * pageNum)

    fun getNextPageArticleByHobbyName(hobbyName: String): LiveData<MutableList<Article>> {
        pageNum++
        return ArticleRepository().getArticleByHobbyName(hobbyName, pageNum, pageSize)
    }

    fun addArticleList(list: MutableList<Article>) {
        _articleList.addAll(list)
    }

    fun updateArticleList(list: MutableList<Article>) {
        _articleList.clear()
        _articleList.addAll(list)
    }

    fun updateChartArticleList(list: MutableList<Article>) {
        _chartArticleList.clear()
        _chartArticleList.addAll(list)
    }

    fun rotationChartArticle(): LiveData<Result> =
        ArticleRepository().rotationChartArticle()

}